#include "LDX.h"
void run()
{
	std::cout<< "sizeof(CameraBuffer)=" << sizeof(ldx::render::CBufferCamera) << std::endl;
	std::cout << "sizeof(CBufferLights)=" << sizeof(ldx::render::CBufferLights) << std::endl;
	std::cout << "sizeof(CBufferMaterial)=" << sizeof(ldx::render::CBufferMaterial) << std::endl;
	std::cout << "sizeof(CBufferModel)=" << sizeof(ldx::render::CBufferModel) << std::endl;
	ldx::device::WinDevice* device = new ldx::device::WinDevice("LDX", 720, 480, true, false, true, true, 0);
	ldx::render::IRenderDriver* render = device->getRenderDriver();
	ldx::scene::CSceneManager* smgr = device->getSceneManager();
	//cube
	ldx::scene::ISceneNode* Cube = smgr->addCubeSceneNode(nullptr,-1, "media//textures//wooden-crate.jpg");
	Cube->setPosition(mt::vec3f(-1,0,10));
	//Cube->setScale(mt::vec3f(0.1f, 0.1f, 0.1f));
	Cube->setRotation(mt::vec3f(60.f, 45.0f, 0.0f));

	ldx::scene::ISceneNode* Cube2 = smgr->addCubeSceneNode(Cube, -1); 
	Cube2->setScale(mt::vec3f(0.5f,0.5f,0.5f));
	Cube2->getMaterial(0).setFlag(ldx::render::EMF_LIGHTING, false);//close lighting.
	Cube2->getMaterial(0).DiffuseColor = ldx::render::SColorf(1.0f, 0.0f, 0.0f, 1.0f);//red
	
	ldx::scene::ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(mt::vec3f(0,-3,0),1.f);
	Cube2->addAnimator(anim);
	anim->drop();
	Cube->update(0.1f);
	Cube2->update(0.1f);
	{
		std::cout << "Print cubes info:\n";
		std::cout << "Cube 1:\n";
		std::cout << "position:" << Cube->getAbsolutePosition().X << \
			"," << Cube->getAbsolutePosition().Y << "," << Cube->getAbsolutePosition().Z << "\n";
		std::cout << "Cube 2:\n";
		std::cout << "position:" << Cube2->getAbsolutePosition().X << \
			"," << Cube2->getAbsolutePosition().Y << "," << Cube2->getAbsolutePosition().Z << "\n";

	}
	//Cube->setScale(mt::vec3f(0.5f, 1.0f, 1.0f));
	//lights
	ldx::scene::CLightSceneNode* light0 = smgr->addSpotLight(ldx::scene::ELMT_STATIC, Cube2, 0,mt::vec4f(-1.f,-1.f,-1.f,1.f),mt::vec3f(2.0f,0.0f,0.0f),0.007f,0.1f);
	//camera
	ldx::scene::ICameraSceneNode* cameraFPS = smgr->addCameraSceneNodeFPS();
	ldx::scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0, mt::vec3f(0, 0, -10));
	//set camera active.
	smgr->setActiveCamera(camera);
	while (device->run())
	{
		//logic update

		//render update
		/*if (!device->isWindowActive())
			device->yield();
		else*/
		{
			device->beginScene(ldx::render::ECF_COLOR_DEPTH_BUFFER, ldx::render::SColorf(0.0f, 0.f,0.f,0.f), 1.0f, 0);
			smgr->drawAll();
			device->endScene();
		}
	}

	device->drop();
}

int main()
{
	try
	{
		run();
	}
	catch (ldx::os::ILDXException e)
	{
		e.print();
	}
	return 0;
}